package simulator;

import java.util.HashMap;
import java.util.List;

import org.apache.commons.math3.stat.StatUtils;

public class StatsEvaluation {

	private HashMap<Net, HashMap<Double, List<Statistics>>> globalStats;

	public StatsEvaluation(	HashMap<Net, HashMap<Double, List<Statistics>>> globalStats) {
		this.globalStats = globalStats;
	}

	public void generateResults() {
		System.out.println("INFO: Evaluating results...");

		for(Net n: globalStats.keySet()){
			System.out.println("*********************\nTopologia: "+n);
			HashMap<Double, List<Statistics>> netStats = globalStats.get(n);


			for(Double alpha: netStats.keySet()){
				System.out.println("-------------\nAlpha: "+alpha + " Beta: " + (1 - alpha));
				List<Statistics> alphaStats = netStats.get(alpha);
				
				System.out.println("Disp %:");
//				for(Statistics s: alphaStats){
					//System.out.print("\t"+s.getDispTime()/s.getTotalTime()*100);
//				}
				double values[] = new double[alphaStats.size()];
				int i = 0;
				for(Statistics s: alphaStats){
					values[i++] = s.getDispTime()/s.getTotalTime()*100;
				}
				System.out.println();
				
				double Z = 1.959961;
				double Desv = Math.sqrt(StatUtils.variance(values));
				System.out.println("Desv= "+ Desv);
				double Hw = 0.5;
				double N  = Math.pow(Z*Desv/Hw, 2);
				System.out.println("n= "+N);

				/*System.out.println("Broken %:");
				for(Statistics s: alphaStats){
					System.out.print("\t"+s.getBroken()/s.getTotalTime()*100);
				}
				System.out.println();
				
				System.out.println("Infec %:");
				for(Statistics s: alphaStats){
					System.out.print("\t"+s.getInfected()/s.getTotalTime()*100);
				}
				System.out.println();
				*/
			}
			
			
			
		}
		
	}

}
